package com.guli.gulimall.member.service.impl;

import com.guli.common.utils.R;
import com.guli.common.vo.MemberTo;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.Query;

import com.guli.gulimall.member.dao.MemberDao;
import com.guli.gulimall.member.entity.MemberEntity;
import com.guli.gulimall.member.service.MemberService;
import org.springframework.web.bind.annotation.RequestParam;


@Service("memberService")
public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> implements MemberService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MemberEntity> page = this.page(
                new Query<MemberEntity>().getPage(params),
                new QueryWrapper<MemberEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public MemberEntity getMemberByToken(String token) {
        return baseMapper.selectOne(new QueryWrapper<MemberEntity>().eq("access_token",token));
    }

    @Override
    public R login( String username, String password) {
        MemberEntity memberEntity = baseMapper.selectOne(new QueryWrapper<MemberEntity>().eq("username", username));
        if (memberEntity!=null){
            if (password.equals(memberEntity.getPassword())){
                return R.ok().setData(memberEntity);
            }
            return R.error();
        }
        return R.error();
    }

}